/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [CalendarPanel.java]
 * Creation Date        [11-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.clock_V2.ui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.GregorianCalendar;
import java.util.TimeZone;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 * 主面板
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class CalendarPanel extends JFrame implements ActionListener {

	private static final long serialVersionUID = -814409501981428045L;

	/** 时间日期对象 */
	public static GregorianCalendar calendar = new GregorianCalendar();
	/** 显示当前时区 */
	private final JLabel timezoneLabel = new JLabel();
	/** 确定, 取消, 应用按钮 */
	private final JButton[] btn = new JButton[3];

	public CalendarPanel() {
		// 设置当前时区为中国标准时区.
		calendar.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));

		setTitle("日期和时间 属性");
		setSize(415, 330);
		Toolkit tk = Toolkit.getDefaultToolkit();
		setLocation((tk.getScreenSize().width - getWidth()) / 2,
				(tk.getScreenSize().height - getHeight()) / 2);
		// 日期, 时间, 时区显示
		DatePanel datePanel = new DatePanel();
		TimePanel timePanel = new TimePanel();
		timezoneLabel.setText("当前时区: "
				+ calendar.getTimeZone().getDisplayName());
		timezoneLabel.setPreferredSize(new Dimension(380, 20));

		JPanel panel1 = new JPanel();
		panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		panel1.add(datePanel);
		panel1.add(timePanel);
		panel1.add(timezoneLabel);

		JTabbedPane pane = new JTabbedPane();
		pane.setSize(395, 260);
		pane.setLocation(5, 5);
		pane.add("时间和日期", panel1);
		pane.add("时区", new JPanel());
		pane.add("Internet 时间", new JPanel());

		JPanel buttonPanel = new JPanel();
		buttonPanel.setSize(395, 30);
		buttonPanel.setLocation(10, 267);
		buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		for (int i = 0; i < btn.length; i++) {
			btn[i] = new JButton();
			btn[i].setPreferredSize(new Dimension(80, 20));
			btn[i].setMargin(new Insets(0, 0, 0, 0));
			btn[i].addActionListener(this);
			buttonPanel.add(btn[i]);
		}
		btn[0].setText("确定");
		btn[1].setText("取消");
		btn[2].setText("关于");

		setLayout(null);
		add(pane);
		add(buttonPanel);

		setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String message = "版本号: V1.0  \n程序编写:不落的太阳  "
				+ "\n日  期 : 2010年8月13日 \nEMAIL : sean.yang1984@gmail.com "
				+ "\n公  司 : Softtek-GE O&G Team";
		if (e.getSource() == btn[2])
			JOptionPane.showMessageDialog(null, message);
		else
			System.exit(0);
	}

}
